package cc.eddic.pratice.programmingparadigms.exam.impl;

import cc.eddic.pratice.programmingparadigms.exam.Gender;
import cc.eddic.pratice.programmingparadigms.exam.MasterDataService;
import cc.eddic.pratice.programmingparadigms.exam.domain.Category;
import cc.eddic.pratice.programmingparadigms.exam.domain.Exam;
import cc.eddic.pratice.programmingparadigms.exam.domain.Student;
import cc.eddic.pratice.programmingparadigms.exam.domain.SubCategory;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

@Slf4j
public class MasterDataServiceGcsImpl implements MasterDataService {

    @Override
    public List<Category> getCategories() {
        Category software = new Category("软件开发基础");

        Category office = new Category("办公软件");
        office.add(new SubCategory("Word")).add(new SubCategory("Excel"));
//        office.add(new SubCategory("Word"));
//        office.add(new SubCategory("Excel"));

        Category coding = new Category("代码");

        return new ArrayList<Category>(Arrays.asList(software, office, coding));
    }

    @Override
    public List<Student> getStudents() {
        return new ArrayList<>(Arrays.asList(
                new Student("李惠", Gender.FEMALE, "计算机"),
                new Student("谭雨晴", Gender.FEMALE, "通信"),
                new Student("李馨", Gender.FEMALE, "计算机"),
                new Student("曾奕哲", Gender.MALE, "计算机"),
                new Student("车晓满", Gender.MALE, "计算机"),
                new Student("王巧家", Gender.MALE, "交通"),
                new Student("孙晨玮", Gender.MALE, "土木"),
                new Student("崔相元", Gender.MALE, "计算机"),
                new Student("韩睿洁", Gender.FEMALE, "计算机")));
    }

    @Override
    public List<Exam> getExams() {
        return new ArrayList<>(Arrays.asList(new Exam("7-12 开营考试"),
                new Exam("7-31 写代码"),
                new Exam("8-15 理论"),
                new Exam("8-25 答辩")));
    }

    @Override
    public <T> Optional<T> find(List<T> genericList, Predicate<T> predicate) {
        if (log.isDebugEnabled()) log.debug("{}", genericList);

        for (T o : genericList) {
            if (predicate.test(o)) {
                return Optional.of(o);
            }
        }
        return Optional.empty();
    }
}
